<template>
	<view>
		<view class="btns" v-if="status == 'START'">
			<view class="solution" @click="startApply">
				接单
			</view>
			<view class="solution red" @click="endApply">
				不接单
			</view>
		</view>
		<view class="btns" v-if="status == 'ACCEPT' || status == 'ACCEPT_CLOSING'">
			<template v-if="tabIndex === 1">
				<template v-if="closeApply === null">
					<view class="solution" @click="showDispatch" v-if="['翻耕整地', '机插秧', '作物收割', '作物播种', '无人机打药','秸秆离田'].includes(serviceProjectName)">
						申请调度
					</view>
					<view class="solution red" @click="popCancel"
						style="border-color: #FF6E6E;color: #FF6E6E;">
						取消订单
					</view>
					<view class="solution" @click="startService">
						开始服务
					</view>
				</template>
				<template v-else>
					<template v-if="closeApply.status === 'QUASH'">
						<view class="solution red" @click="showComplain">
							订单投诉
						</view>
						<view class="solution" @click="showDispatch" v-if="['翻耕整地', '机插秧', '作物收割', '作物播种', '无人机打药','秸秆离田'].includes(serviceProjectName)">
							申请调度
						</view>
						<view class="solution red" @click="popCancel"
							style="border-color: #FF6E6E;color: #FF6E6E; padding: 0 5rpx;">
							{{closeApply.personalFirst ? '' : '再次'}}取消订单
						</view>
						<view class="solution" @click="startService">
							开始服务
						</view>
						<view class="solution"  v-show="complainApply && complainApply.reasonId" @click="lookComplainReason">
							投诉原因
						</view>
					</template>
					<template v-else-if="closeApply.status === 'TBC'">
						<template v-if="closeApply && closeApply.applyPersonType === 'ORDER_SIDE'">
							<view class="solution"  style="width: 60px;"@click="agree">
								同意
							</view>
							<view class="solution red" @click="reject" style="border-color: #FF6E6E;color: #FF6E6E;">
								拒绝
							</view>
						</template>
						<template v-else-if="closeApply && closeApply.applyPersonType === 'SERVER_SIDE'">
							<view class="solution" @click="repealOrder">
								撤销取消订单
							</view>
						</template>
					</template>
					<template v-else-if="closeApply.status === 'REJECT'">
						<view class="solution red" @click="showComplain"
							v-show="!closeApply.personalFirst">
							订单投诉
						</view>
						<view class="solution" @click="showDispatch" v-if="['翻耕整地', '机插秧', '作物收割', '作物播种', '无人机打药','秸秆离田'].includes(serviceProjectName)">
							申请调度
						</view>
						<view class="solution red" @click="popCancel"
							style="border-color: #FF6E6E;color: #FF6E6E;padding: 0 4rpx;">
							{{closeApply.personalFirst ? '' : '再次'}}取消订单
						</view>
						<view class="solution" @click="startService">
							开始服务
						</view>
						<view class="solution"  v-show="complainApply && complainApply.reasonId" @click="lookComplainReason">
							投诉原因
						</view>
					</template>
					<view class="solution" v-show="closeApply && closeApply.reasonId" @click="lookCancelReason">
						取消原因
					</view>
				</template>
			</template>
		</view>
		<view class="btns" v-if="status == 'DOING' || status == 'DOING_CLOSING'">
			<template v-if="closeApply === null">
				<view class="solution" @click="showDispatch" v-if="['翻耕整地', '机插秧', '作物收割', '作物播种', '无人机打药','秸秆离田'].includes(serviceProjectName)">
					申请调度
				</view>
				<view class="solution red" @click="popCancel"
					style="border-color: #FF6E6E;color: #FF6E6E;">
					取消订单
				</view>
				<view class="solution" @click="endService">
					服务完成
				</view>
			</template>
			<template v-else>
				<template v-if="closeApply.status === 'QUASH'">
					<view class="solution red" @click="showComplain">
						订单投诉
					</view>
					<view class="solution" @click="showDispatch" v-if="['翻耕整地', '机插秧', '作物收割', '作物播种', '无人机打药','秸秆离田'].includes(serviceProjectName)">
						申请调度
					</view>
					<view class="solution red" @click="popCancel"
						style="border-color: #FF6E6E;color: #FF6E6E;padding: 0 5rpx;">
						{{closeApply.personalFirst ? '' : '再次'}}取消订单
					</view>
					<view class="solution" @click="endService">
						服务完成
					</view>
					<view class="solution"  v-show="complainApply && complainApply.reasonId" @click="lookComplainReason">
						投诉原因
					</view>
				</template>
				<template v-else-if="closeApply.status === 'TBC'">
					<template v-if="closeApply && closeApply.applyPersonType === 'ORDER_SIDE'">
						<view class="solution" @click="agree">
							同意
						</view>
						<view class="solution red" @click="reject" style="border-color: #FF6E6E;color: #FF6E6E;">
							拒绝
						</view>
					</template>
					<template v-else-if="closeApply && closeApply.applyPersonType === 'SERVER_SIDE'">
						<view class="solution" @click="repealOrder">
							撤销取消订单
						</view>
					</template>
				</template>
				<template v-else-if="closeApply.status === 'REJECT'">
					<view class="solution red" @click="showComplain"
						v-show="!closeApply.personalFirst">
						订单投诉
					</view>
					<view class="solution" @click="showDispatch" v-if="['翻耕整地', '机插秧', '作物收割', '作物播种', '无人机打药','秸秆离田'].includes(serviceProjectName)">
						申请调度
					</view>
					<view class="solution red" @click="popCancel"
						style="border-color: #FF6E6E;color: #FF6E6E;padding: 0 4rpx;">
						{{closeApply.personalFirst ? '' : '再次'}}取消订单
					</view>
					<view class="solution" @click="endService">
						服务完成
					</view>
					<view class="solution"  v-show="complainApply && complainApply.reasonId" @click="lookComplainReason">
						投诉原因
					</view>
				</template>
				<view class="solution" v-show="closeApply && closeApply.reasonId" @click="lookCancelReason">
					取消原因
				</view>
			</template>
		</view>
		<view class="btns" v-if="status == 'ACCEPT_APPEAL' || status == 'DOING_APPEAL' || status == 'DONE_APPEAL'">
			<view class="solution" @click="repealComplain"
				v-show="complainApply.complainant === 'SERVER_SIDE'">
				撤销投诉
			</view>
			<view class="solution"  v-show="complainApply && complainApply.reasonId" @click="lookComplainReason">
				投诉原因
			</view>
		</view>
		<view class="btns" v-if="status == 'PAID' || status == 'COMMENTED' || status == 'END'">
			<view class="solution" @click="lookAppraise">
				查看评价
			</view>
			<view class="solution red" @click="delOrder" style="border-color: #FF6E6E;color: #FF6E6E;">
				删除订单
			</view>
		</view>
		<view class="btns" v-if="status == 'CLOSE'">
			<view class="solution" v-show="closeApply && closeApply.reasonId" @click="lookCancelReason">
				取消原因
			</view>
			<view class="solution red" @click="delOrder" style="border-color: #FF6E6E;color: #FF6E6E;">
				删除订单
			</view>
		</view>
		<view class="btns" v-if="tabIndex === 5">
			<view class="solution red" @click="delOrder" style="border-color: #FF6E6E;color: #FF6E6E;">
				删除订单
			</view>
		</view>
		<view class="btns" v-if="tabIndex === 2 && status == 'DONE'">
			<view class="solution red" @click="showComplain">
				订单投诉
			</view>
			<view class="solution"  v-show="complainApply && complainApply.reasonId" @click="lookComplainReason">
				投诉原因
			</view>
		</view>
		<!-- operate -->
		<u-popup class="popUp" :show="popCancelFlag" :round="10" mode="bottom" width="100%" height="100%"
			:closeable="false" @close="popCancelFlag=false">
			<view class="popUpOperate">
				<view class="left" @click="popCancelFlag=false">
					取消
				</view>
				<view class="center">
					取消订单
				</view>
				<view class="right" @click="popConfirm">
					确认
				</view>
			</view>
			<view class="contents">
				<view class="radio">
					<u-radio-group
					    v-model="radiovalue1"
					    iconPlacement="right"
					     placement="column"
						 size="32"
					  >
					    <u-radio
					      :customStyle="{marginBottom: '8px'}"
					      v-for="(item, index) in radiolist1"
					      :key="item.id"
					      :label="item.name"
					      :name="item.id"
					    >
					    </u-radio>
					  </u-radio-group>
				</view>
				<view class="textarea" v-show="radiovalue1 !== null">
					<u--textarea type="textarea" v-model="popData.content" placeholder="点击输入取消原因"
						style="height: 100%;width: 100%;padding: 10rpx;" height="200" count>
					</u--textarea>
				</view>
				<imageVideo @imageOrVideo="imageOrVideo"></imageVideo>
			</view>
		</u-popup>
		<u-popup class="popUp" :show="complainFlag" :round="10" mode="bottom" width="100%" height="100%"
			:closeable="false" @close="complainFlag=false">
			<view class="popUpOperate">
				<view class="left" @click="complainFlag=false">
					取消
				</view>
				<view class="center">
					投诉原因
				</view>
				<view class="right" @click="complainConfirm">
					确认
				</view>
			</view>
			<view class="contents">
				<view class="radio">
					<u-radio-group
					    v-model="radiovalue2"
					    iconPlacement="right"
					     placement="column"
						 size="32"
					  >
					    <u-radio
					      :customStyle="{marginBottom: '8px'}"
					      v-for="(item, index) in radiolist2"
					      :key="item.id"
					      :label="item.name"
					      :name="item.id"
					    >
					    </u-radio>
					  </u-radio-group>
				</view>
				<view class="textarea" v-show="radiovalue2 !== null">
					<u--textarea type="textarea" v-model="popData.complainContent" placeholder="点击输入投诉原因"
						style="height: 100%;width: 100%;padding: 10rpx;" height="200" count>
					</u--textarea>
				</view>
				<imageVideo @imageOrVideo="imageOrVideo"></imageVideo>
			</view>
		</u-popup>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog cancelText="关闭" confirmText="同意" title="删除提示" content="确定删除此订单吗？" @confirm="delConfirm"
				@close="delClose"></uni-popup-dialog>
		</uni-popup>
		<u-popup class="popUp" :show="dispatchFlag" :round="10" mode="bottom" width="100%" height="100%"
			:closeable="false" @close="dispatchFlag=false">
			<view class="popUpOperate">
				<view class="left" @click="dispatchFlag=false">
					取消
				</view>
				<view class="center">
					调度原因
				</view>
				<view class="right" @click="dispatchConfirm">
					确认
				</view>
			</view>
			<view class="contents contents2">
				<view class="item">
					<view class="left">
						调度类型：
					</view>
					<view class="right" @click="showTypeFlag = true">
						<view class="dropdown-trigger">
							{{ popData.type ? popData.type : '请选择调度类型' }}
							<view class="dropdown-list" v-if="showTypeFlag">
								<view class="dropdown-item" v-for="item in typeList" @click.stop="selectItem(item)"
									:key="item.type">
									{{ item.name }}
								</view>
							</view>
						</view>

					</view>
				</view>
				<view class="textarea">
					<u--textarea type="textarea" v-model="popData.dispatchContent" placeholder="点击输入调度原因"
						style="height: 100%;width: 100%;padding: 10rpx;" height="200" count>
					</u--textarea>
				</view>

				<imageVideo @imageOrVideo="imageOrVideo"></imageVideo>
			</view>
		</u-popup>
		<u-popup class="popUp" :show="endServiceFlag" :round="10" mode="bottom" width="100%" height="100%"
			:closeable="false" @close="endServiceFlag=false">
			<view class="popUpOperate">
				<view class="left" @click="endServiceFlag=false">
					取消
				</view>
				<view class="center">
					服务完成
				</view>
				<view class="right" @click="endServiceConfirm">
					确认
				</view>
			</view>
			<view class="contents">
				<view class="item" style="margin-top: 0;">
					<view class="left">
						实际服务亩数：
					</view>
					<view class="right">
						<u--input v-model="formData.area" placeholder='请输入实际服务亩数' border="none"></u--input>
					</view>
				</view>
				<view class="item">
					<view class="left">
						实际服务价格：
					</view>
					<view class="right">
						<u--input v-model="formData.price" placeholder='请输入实际服务价格' border="none"></u--input>
					</view>
				</view>
				<view class="item">
					<view class="left">
						服务完成时间：
					</view>
					<view class="right" @click="showTimeDialog">
						<u--input v-model="formData.time" placeholder='请输入服务完成时间' border="none"></u--input>
						<u-datetime-picker :show="showTimeStartFlag" mode="datetime" @confirm="getShowTime"
							:formatter='formatter' v-model="endServiceTime" @cancel="showTimeStartFlag=false">
							:placeholder='请输入服务亩数'
						</u-datetime-picker>
					</view>
				</view>
				<imageVideo @imageOrVideo="imageOrVideo"></imageVideo>
			</view>
		</u-popup>
		<u-popup class="popUp" :show="endServiceFlag2" :round="10" mode="bottom" width="100%" height="100%"
			:closeable="false" @close="endServiceFlag2=false">
			<view class="popUpOperate">
				<view class="left" @click="endServiceFlag2=false">
					取消
				</view>
				<view class="center">
					服务完成
				</view>
				<view class="right" @click="endServiceConfirm2">
					确认
				</view>
			</view>
			<view class="contents">
				<view class="item">
					<view class="left">
						实际服务价格：
					</view>
					<view class="right">
						<u--input v-model="formData.price" placeholder='请输入实际服务价格' border="none"></u--input>
					</view>
				</view>
				<view class="item">
					<view class="left">
						直播开始时间：
					</view>
					<view class="right" @click="showTimeDialog">
						<u--input v-model="formData.actualServiceBegin" placeholder='请输入直播开始时间' border="none"></u--input>
						<u-datetime-picker :show="showTimeStartFlag" mode="datetime" @confirm="getBeginTime2"
							:formatter='formatter' v-model="formData.actualServiceBegin" @cancel="showTimeStartFlag=false">
						</u-datetime-picker>
					</view>
				</view>
				<view class="item">
					<view class="left">
						直播结束时间：
					</view>
					<view class="right" @click="showTimeDialog">
						<u--input v-model="formData.actualServiceEnd" placeholder='请输入直播结束时间' border="none"></u--input>
						<u-datetime-picker :show="showTimeStartFlag" mode="datetime" @confirm="getBeginTime2"
							:formatter='formatter' v-model="formData.actualServiceEnd" @cancel="showTimeStartFlag=false">
						</u-datetime-picker>
					</view>
				</view>
				<imageVideo @imageOrVideo="imageOrVideo"></imageVideo>
			</view>
		</u-popup>
		<u-popup class="popUp accept" :show="acceptFlag" :round="10" mode="bottom" width="100%" height="100%"
			:closeable="false" @close="acceptFlag=false">
			<view class="popUpOperate">
				<view class="left" @click="acceptFlag=false">
					取消
				</view>
				<view class="center">
					确认接单
				</view>
				<view class="right" @click="acceptConfirm">
					确认
				</view>
			</view>
			<view class="contents">
				<view class="item">
					<view class="left">
						直播开始时间：
					</view>
					<view class="right" @click="showTimeDialog">
						<u--input v-model="formData.serviceBegin" placeholder='请输入直播开始时间' border="none"></u--input>
						<u-datetime-picker :show="showTimeStartFlag" mode="datetime" @confirm="getBeginTime"
							:formatter='formatter' v-model="formData.serviceBegin" @cancel="showTimeStartFlag=false">
						</u-datetime-picker>
					</view>
				</view>
				<view class="item">
					<view class="left">
						直播结束时间：
					</view>
					<view class="right" @click="showTimeDialog">
						<u--input v-model="formData.serviceEnd" placeholder='请输入直播结束时间' border="none"></u--input>
						<u-datetime-picker :show="showTimeStartFlag" mode="datetime" @confirm="getEndTime"
							:formatter='formatter' v-model="formData.serviceEnd" @cancel="showTimeStartFlag=false">
						</u-datetime-picker>
					</view>
				</view>
				<view class="item">
					<view class="left" style="width: 80px;">
						联系人：
					</view>
					<view class="right">
						<u--input v-model="formData.servicerUserName" placeholder='请输入联系人' border="none"></u--input>
					</view>
				</view>
				<view class="item">
					<view class="left">
						联系电话：
					</view>
					<view class="right">
						<u--input v-model="formData.servicerUserPhone" placeholder='请输入联系电话' border="none"></u--input>
					</view>
				</view>
			</view>
		</u-popup>
		<u-popup class="popUp accept" :show="acceptFlag1" :round="10" mode="bottom" width="100%" height="100%"
			:closeable="false" @close="acceptFlag1=false">
			<view class="popUpOperate">
				<view class="left" @click="acceptFlag1=false">
					取消
				</view>
				<view class="center">
					确认接单
				</view>
				<view class="right" @click="acceptConfirm1">
					确认
				</view>
			</view>
			<view class="contents">
				<view class="item">
					<view class="left" style="width: 80px;">
						联系人：
					</view>
					<view class="right">
						<u--input v-model="formData.servicerUserName" placeholder='请输入联系人' border="none"></u--input>
					</view>
				</view>
				<view class="item">
					<view class="left">
						联系电话：
					</view>
					<view class="right">
						<u--input v-model="formData.servicerUserPhone" placeholder='请输入联系电话' border="none"></u--input>
					</view>
				</view>
			</view>
		</u-popup>
		<u-popup class="popUp" :show="lookCancelFlag" :round="10" mode="bottom" width="100%" height="100%"
			:closeable="false" @close="lookCancelFlag=false">
			<view class="popUpOperate popUpOperate1">
				<view class="center">
					取消原因
				</view>
			</view>
			<view class="contents">
				<view class="lookCancel">
					<view class="reason" v-if="closeApply">
						{{closeApply.applyPersonType === 'ORDER_SIDE' ? '下单方取消' : '服务方取消'}}
					</view>
					<view class="reason" v-if="closeApply">
						{{closeApply.reasonName}}
					</view>
					<view class="reason" v-if="closeApply">
						备注：{{closeApply.reason}}
					</view>
					<view class="imgs" v-if="closeApply && closeApply.pictureList">
						<image :src="item" mode="widthFix" class="img" v-for="(item,index) in closeApply.pictureList" :key="index"></image>
					</view>
					<view class="vedio" v-if="closeApply && closeApply.vedio">
						<MyVideo :videoUrl="closeApply.vedio"
							style="width: 100%;min-width: 600rpx;height: 420rpx;" class="video"></MyVideo>
					</view>
				</view>
			</view>
		</u-popup>
		<u-popup class="popUp" :show="lookComplainFlag" :round="10" mode="bottom" width="100%" height="100%"
			:closeable="false" @close="lookComplainFlag=false">
			<view class="popUpOperate popUpOperate1">
				<view class="center">
					投诉原因
				</view>
			</view>
			<view class="contents">
				<view class="lookCancel">
					<view class="reason" v-if="complainApply">
						投诉人：{{complainApply.createUserName}}
					</view>
					<view class="reason" v-if="complainApply">
						{{complainApply.reasonName}}
					</view>
					<view class="reason" v-if="complainApply">
						备注：{{complainApply.remark}}
					</view>
					<view class="imgs" v-if="complainApply && complainApply.pictureList">
						<image :src="item" mode="widthFix" class="img" v-for="(item,index) in complainApply.pictureList" :key="index"></image>
					</view>
					<view class="vedio" v-if="complainApply && complainApply.vedio">
						<MyVideo :videoUrl="complainApply.vedio"
							style="width: 100%;min-width: 600rpx;height: 420rpx;" class="video"></MyVideo>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		socializedBaseurl
	} from '@/config/baseUrl.js'
	import imageVideo from '../../components/image-video/index.vue'
	import API from '@/api/socialized-servce/farm-service/mechanist/my-order/index.js'
	import MyVideo from '@/subPage1/components/myVideo/myVideo.vue'
	export default {
		data() {
			return {
				acceptFlag: false,
				acceptFlag1: false,
				popCancelFlag: false,
				popData: {
					type: '',
					content: '',
					complainContent: '',
					completeContent: '',
					dispatchContent: '',
				},
				complainFlag: false,
				completeFlag: false,
				dispatchFlag: false,
				endServiceTime: Number(new Date()),
				endServiceFlag: false,
				showTimeStartFlag: false,
				formData: {
					area: '',
					price: '',
					time: this.getTime(Number(new Date()))
				},
				imgList: [],
				videoList: [],
				showTypeFlag: false,
				typeList: [{
						name: '调度操作员',
						type: 1
					},
					{
						name: '调度时间',
						type: 2
					},
					{
						name: '调度时间和操作员',
						type: 3
					}
				],
				endServiceFlag2: false,
				lookCancelFlag: false,
				lookComplainFlag: false,
				radiovalue1: null,
				radiovalue2: null,
				radiolist1: [],
				radiolist2: []
			}
		},
		props: {
			svcObjId: {
				type: Number,
				default: ''
			},
			id: {
				type: Number,
				default: ''
			},
			status: {
				type: String,
				default: ''
			},
			orderId: {
				type: String,
				default: ''
			},
			properties: {
				type: Array,
				default: []
			},
			serviceProperties: {
				type: Array,
				default: []
			},
			orderAmount: {
				type: String,
				default: ''
			},
			contactPhone: {
				type: String,
				default: ''
			},
			organizationNo: {
				type: String,
				default: ''
			},
			closeApply: {
				type: Object,
				default: null
			},
			complainApply: {
				type: Object,
				default: null
			},
			tabIndex: {
				type: Number,
				default: null
			},
			evaluated: {
				type: Boolean,
				default: false
			},
			serviceProjectName: {
				type: String,
				default: ''
			}
		},
		components: {
			imageVideo,
			MyVideo
		},
		created() {
			this.radiolist1 = uni.getStorageSync('radiolist1')
			this.radiolist2 = uni.getStorageSync('radiolist2')
			if (this.properties && this.serviceProjectName != '直播带货') {
				this.formData.area = this.properties.filter(el => el.expression === 'rate')[0].numValue
			}
			if (this.orderAmount) {
				this.$set(this.formData, 'price', this.orderAmount)
			}
		},
		methods: {
			startApply() {
				if (this.properties) {
					let serviceBegin = this.properties.filter(el => el.expression === 'serviceBegin')[0].textValue
					this.$set(this.formData, 'serviceBegin', this.formatTime(serviceBegin))
					let serviceEnd = this.properties.filter(el => el.expression === 'serviceEnd')[0].textValue
					this.$set(this.formData, 'serviceEnd', this.formatTime(serviceEnd))
					this.$set(this.formData, 'servicerUserId', this.properties.filter(el => el.expression === 'serviceUserId')[0].textValue)
				}
				if (this.serviceProperties) {
					this.$set(this.formData, 'servicerUserName', this.serviceProperties.filter(el => el.expression === 'serviceName')[0].textValue)
					this.$set(this.formData, 'servicerUserPhone', this.serviceProperties.filter(el => el.expression === 'servicePhone')[0].textValue)
				}
				this.acceptFlag = true
			},
			async acceptConfirm() {
				let params = {
					orderNo: this.orderId,
					serviceBegin: this.getTimes(this.formData.serviceBegin),
					serviceEnd: this.getTimes(this.formData.serviceEnd),
					servicerUserId: this.formData.servicerUserId,
					servicerUserName: this.formData.servicerUserName,
					servicerUserPhone: this.formData.servicerUserPhone,
					checkStatus: 'YES'
				}
				let res = await API.startApply(params)
				this.acceptFlag = false
				if (res.code === 200) {
					this.$emit('updateOrder')
					uni.showToast({
						title: '操作成功',
						icon: 'success'
					})
				} else {
					uni.showToast({
						title: '操作失败',
						icon: 'none'
					})
				}
			},
			async endApply() {
				if (this.properties) {
					this.$set(this.formData, 'servicerUserId', this.properties.filter(el => el.expression === 'serviceUserId')[0].textValue)
				}
				if (this.serviceProperties) {
					this.$set(this.formData, 'servicerUserName', this.serviceProperties.filter(el => el.expression === 'serviceName')[0].textValue)
					this.$set(this.formData, 'servicerUserPhone', this.serviceProperties.filter(el => el.expression === 'servicePhone')[0].textValue)
				}
				this.acceptFlag1 = true
			},
			async acceptConfirm1() {
				let params = {
					orderNo: this.orderId,
					checkStatus: 'NO',
					servicerUserId: this.formData.servicerUserId,
					servicerUserName: this.formData.servicerUserName,
					servicerUserPhone: this.formData.servicerUserPhone,
				}
				let res = await API.startApply(params)
				if (res.code === 200) {
					this.acceptFlag1 = false
					this.$emit('updateOrder')
					uni.showToast({
						title: '操作成功',
						icon: 'success'
					})
				} else {
					uni.showToast({
						title: '操作失败',
						icon: 'none'
					})
				}
			},
			async startService() {
				let params = {
					orderNo: this.orderId
				}
				let res = await API.startService(params)
				if (res.code === 200) {
					this.$emit('updateOrder')
					uni.showToast({
						title: '操作成功',
						icon: 'success'
					})
				} else {
					uni.showToast({
						title: '操作失败',
						icon: 'none'
					})
				}
			},
			popCancel() {
				this.popData.content = ''
				this.imgList = []
				this.videoList = []
				this.popCancelFlag = true
			},
			async popConfirm() {
				if(this.radiovalue1 === null) {
					uni.showToast({
						title: '请选择取消原因',
						icon: 'error'
					})
				} else {
					let {
						content
					} = this.popData
					let params = {
						orderNo: this.orderId,
						applyPersonType: 'SERVER_SIDE',
						reason: content,
						pictureList: [],
						vedio: '',
						reasonId: this.radiovalue1
					}
					this.imgList.forEach(el => params.pictureList.push(el.imgUrl))
					this.videoList.forEach(el => params.vedio = el.videoUrl)
					let res = await API.applayCancelOrder(params)
					if (res.code === 200) {
						this.$emit('updateOrder')
						uni.showToast({
							title: '操作成功',
							icon: 'success'
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'error'
						})
					}
					this.popCancelFlag = false
				}
			},
			async repealOrder() {
				let params = {
					orderNo: this.orderId,
					applyPersonType: 'SERVER_SIDE',
					closeResult: false,
				}
				let res = await API.confirmCancel(params)
				if (res.code === 200) {
					this.$emit('updateOrder')
					uni.showToast({
						title: '操作成功',
						icon: 'success'
					})
				}
				uni.showToast({
					title: res.msg,
					icon: 'none'
				})
			},
			showComplain() {
				this.popData.complainContent = ''
				this.complainFlag = true
			},
			async complainConfirm() {
				if(this.radiovalue2 === null) {
					uni.showToast({
						title: '请选择投诉原因',
						icon: 'error'
					})
				} else {
					let {
						complainContent
					} = this.popData
					let params = {
						orderNo: this.orderId,
						complainant: 'SERVER_SIDE',
						remark: complainContent,
						pictureList: [],
						vedio: '',
						reasonId: this.radiovalue2
					}
					this.imgList.forEach(el => params.pictureList.push(el.imgUrl))
					this.videoList.forEach(el => params.vedio = el.videoUrl)
					let res = await API.orderComplaint(params)
					if (res.code === 200) {
						this.$emit('updateOrder')
						uni.showToast({
							title: '操作成功',
							icon: 'success'
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'error'
						})
					}
					this.complainFlag = false
				}
			},
			async repealComplain() {
				let res = await API.repealOrderComplaint(this.orderId)
				if (res.code === 200) {
					uni.showToast({
						title: '操作成功',
						icon: 'success'
					})
					this.$emit('updateOrder')
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'error'
					})
				}
			},
			showDispatch() {
				this.popData.dispatchContent = ''
				this.popData.type = ''
				this.dispatchFlag = true
			},
			async dispatchConfirm() {
				if (this.popData.type === '') {
					uni.showToast({
						title: '请选择调度类型',
						icon: 'error'
					})
					return
				}
				if (this.popData.dispatchContent === '') {
					uni.showToast({
						title: '请输入调度原因',
						icon: 'error'
					})
					return
				}
				let {
					dispatchContent,
					type
				} = this.popData
				let params = {
					dispatchType: this.typeList.filter(el => el.name === type)[0].type,
					orderNo: this.orderId,
					remark: dispatchContent,
					picture: '',
					vedio: '',
					organizationNo: this.organizationNo,
					contactPhone: this.contactPhone
				}
				if (this.imgList.length > 0) params.picture = this.imgList[0].imgUrl
				if (this.videoList.length > 0) params.vedio = this.videoList[0].videoUrl
				let res = await API.applyScheduling(params)
				if (res.code === 200) {
					uni.showToast({
						title: '申请调度成功',
						icon: 'success'
					})
					this.$emit('updateOrder')
					this.dispatchFlag = false
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'error'
					})
				}
			},
			async agree() {
				let params = {
					orderNo: this.orderId,
					applyPersonType: 'SERVER_SIDE',
					closeResult: true,
				}
				let res = await API.confirmCancel(params)
				if (res.code === 200) {
					this.$emit('updateOrder')
					uni.showToast({
						title: '操作成功',
						icon: 'success'
					})
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'error'
					})
				}
			},
			async reject() {
				let params = {
					orderNo: this.orderId,
					applyPersonType: 'SERVER_SIDE',
					closeResult: false,
				}
				let res = await API.confirmCancel(params)
				if (res.code === 200) {
					this.$emit('updateOrder')
					uni.showToast({
						title: '操作成功',
						icon: 'success'
					})
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'error'
					})
				}
			},
			endService() {
				if (this.serviceProjectName == '直播带货') {
					let serviceBegin = this.properties.filter(el => el.expression === 'serviceBegin')[0].textValue
					this.$set(this.formData, 'actualServiceBegin', this.formatTime(serviceBegin))
					let serviceEnd = this.properties.filter(el => el.expression === 'serviceEnd')[0].textValue
					this.$set(this.formData, 'actualServiceEnd', this.formatTime(serviceEnd))
					this.endServiceFlag2 = true
				} else {
					this.endServiceFlag = true
				}
			},
			showTimeDialog() {
				this.showTimeStartFlag = true
			},
			getShowTime(e) {
				this.formData.time = this.getTime(e.value)
				this.showTimeStartFlag = false
			},
			getBeginTime(e) {
				this.formData.serviceBegin = this.getTime(e.value)
				this.showTimeStartFlag = false
			},
			getEndTime(e) {
				this.formData.serviceEnd = this.getTime(e.value)
				this.showTimeStartFlag = false
			},
			async endServiceConfirm() {
				let {
					area,
					price,
					time
				} = this.formData
				let imgUrl = ''
				let videoUrl = ''
				if (this.imgList.length > 0) {
					imgUrl = this.imgList[0].imgUrl
				}
				if (this.videoList.length > 0) {
					videoUrl = this.videoList[0].videoUrl
				}
				let params = {}
				this.properties.forEach(el=>{
					let key = el.propertyCode
					if(el.expression === 'payRate') {
						params[key] = area
					}
					if(el.expression === 'payAmount') {
						params[key] = price
					}
					if(el.expression === 'actualServiceEnd') {
						params[key] = this.getTimes(time)
					}
					if(el.expression === 'actualServicePicture') {
						params[key] = imgUrl
					}
					if(el.expression === 'actualServiceVedio') {
						params[key] = videoUrl
					}
					
				})
				let res = await API.completedService(this.orderId, params)
				if (res.code === 200) {
					this.$emit('updateOrder')
					uni.showToast({
						title: '操作成功',
						icon: 'success'
					})
					this.endServiceFlag = false
				} else {
					uni.showToast({
						title: '操作失败',
						icon: 'error'
					})
				}
			},
			getBeginTime2(e) {
				this.formData.actualServiceBegin = this.getTime(e.value)
				this.showTimeStartFlag = false
			},
			getEndTime2(e) {
				this.formData.actualServiceEnd = this.getTime(e.value)
				this.showTimeStartFlag = false
			},
			async endServiceConfirm2() {
				let {
					price,
					actualServiceBegin,
					actualServiceEnd
				} = this.formData
				let imgUrl = ''
				let videoUrl = ''
				if (this.imgList.length > 0) {
					imgUrl = this.imgList[0].imgUrl
				}
				if (this.videoList.length > 0) {
					videoUrl = this.videoList[0].videoUrl
				}
				let params = {}
				this.properties.forEach(el=>{
					let key = el.propertyCode
					if(el.expression === 'payAmount') {
						params[key] = price
					}
					if(el.expression === 'actualServiceBegin') {
						params[key] = this.getTimes(actualServiceBegin)
					}
					if(el.expression === 'actualServiceEnd') {
						params[key] = this.getTimes(actualServiceEnd)
					}
					if(el.expression === 'actualServicePicture') {
						params[key] = imgUrl
					}
					if(el.expression === 'actualServiceVedio') {
						params[key] = videoUrl
					}
					
				})
				let res = await API.completedService(this.orderId, params)
				if (res.code === 200) {
					this.$emit('updateOrder')
					uni.showToast({
						title: '操作成功',
						icon: 'success'
					})
					this.endServiceFlag = false
				} else {
					uni.showToast({
						title: '操作失败',
						icon: 'error'
					})
				}
			},
			lookAppraise() {
				if(this.evaluated === null || this.evaluated === false) {
					uni.showToast({
							title: '暂无评价',
							icon: 'none'
					})
				} else {
					uni.navigateTo({
						url: `/subPage1/socialized-service/farm-service/mechanist/look-appraise/look-appraise?orderNo=${this.orderId}`
					})
				}
			},
			delOrder() {
				this.$refs.alertDialog.open()
			},
			delClose() {
				this.$refs.alertDialog.close()
			},
			async delConfirm() {
				if(this.tabIndex === 5) {
					let res = await API.delDispatchOrder(this.orderId)
					if (res.code === 200) {
						this.$emit('updateOrder')
						uni.showToast({
							title: '操作成功',
							icon: 'success'
						})
					} else {
						uni.showToast({
							title: '操作失败',
							icon: 'error'
						})
					}
					return
				}
				let res = await API.delOrder(this.orderId)
				if (res.code === 200) {
					this.$emit('updateOrder')
					uni.showToast({
						title: '操作成功',
						icon: 'success'
					})
				} else {
					uni.showToast({
						title: '操作失败',
						icon: 'error'
					})
				}
			},
			formatter(type, value) {
				if (type === 'year') {
					return value + '年'
				} else if (type === 'month') {
					return value + '月'
				} else if (type === 'day') {
					return value + '日'
				} else if (type === 'hour') {
					return value + '时'
				} else if (type === 'minute') {
					return value + '分'
				} else if (type === 'second') {
					return value + '秒'
				}
				return value
			},
			getTime(timestamp) {
				let date = new Date()
				if (timestamp) date = new Date(timestamp);
				const Y = date.getFullYear() + '-';
				const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				const D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
				const h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
				const m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
				const s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
				return Y + M + D + h + m + s;
			},
			getTimes(timestamp) {
				let date = new Date()
				if (timestamp) date = new Date(timestamp);
				const Y = date.getFullYear();
				const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
				const D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
				const h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours());
				const m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
				const s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
				return `${Y}${M}${D}${h}${m}${s}`;
			},
			imageOrVideo(e) {
				this.imgList = e.imgList
				this.videoList = e.videoList
			},
			selectItem(item) {
				this.popData.type = item.name
				this.showTypeFlag = false
			},
			formatTime(time) {
				let Y = time.slice(0, 4) + '-'
				let M = time.slice(4, 6) + '-'
				let D = time.slice(6, 8) + ' '
				let h = time.slice(8, 10) + ':'
				let m = time.slice(10, 12) + ':'
				let s = time.slice(12)
				return Y + M + D + h + m + s
			},
			lookCancelReason() {
				this.lookCancelFlag = true
			},
			lookComplainReason() {
				this.lookComplainFlag = true
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btns {
		border-top: 1px solid #EFEFEF;
		padding-top: 10rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-end;
	}

	.solution {
		padding: 0 16rpx;
		margin-right: 10rpx;
		margin-bottom: 10rpx;
		height: 58rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #888888;
		text-align: center;
		line-height: 58rpx;
		box-shadow: 0px 0px 4px 1px rgba(0, 0, 0, 0.16);
		border-radius: 15px 15px 15px 15px;
		border: 2px solid #888888;
		
		&.red {
			color: #fd8f8f;
			border: 2px solid #fd8f8f;
		}
	}

	.unsolution {
		background: linear-gradient(135deg, #FF6E6E 0%, #F73737 100%);
	}

	.popUpOperate {
		position: relative;
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 100rpx;
		padding: 0 20rpx;
		border-bottom: 1px solid #ccc;

		.left,
		.right {
			color: #0079fe;
		}

		.center {
			font-weight: 700;
		}
	}
	
	.popUpOperate1 {
		justify-content: center;
	}

	.contents {
		padding: 0 20rpx;
		margin-top: 20rpx;

		.textarea {
			margin-top: 10rpx;
			height: 260rpx;
			width: 100%;
			background-color: #fff;
			
			/deep/ .u-textarea {
				box-sizing: border-box;
				width: 100%!important;
				display: inline-block!important;
			}
		}

		.upload {
			height: 96rpx;
			display: flex;
			align-items: center;

			.text {
				font-size: 24rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #2265FB;
				text-decoration: underline;
			}
		}
		
		.lookCancel {
			font-size: 32rpx;
			.reason {
				margin-bottom: 10rpx;
			}
			
			.imgs {
				display: flex;
				width: 100%;
			
				.img {
					margin-left: 20rpx;
					flex: 1;
					max-width: 50%;
					
					&:first-child {
						margin-left: 0;
					}
				}
				
				margin-bottom: 10rpx;
			}
		}
		
		.item {
			display: flex;
			align-items: center;
			width: 100%;
			margin-top: 20rpx;

			.left {
				font-size: 32rpx
			}

			.right {
				padding: 10rpx;
				flex: 1;
				border: 1px solid #ccc;

				.dropdown-trigger {
					display: flex;
					align-items: center;
					padding-left: 20rpx;
					position: relative;
					height: 60rpx;
					width: 100%;

				}

				.dropdown-list {
					width: 100%;
					position: absolute;
					top: 90rpx;
					left: -20rpx;
					z-index: 999;
					background-color: #fff;
					padding: 10rpx;
					border: 2rpx solid #ccc;
					border-radius: 20rpx;

					.dropdown-item {
						margin-bottom: 5rpx;

						&:hover {
							background-color: pink;
						}
					}
				}
			}
		}
	}

	.contents2 {
		height: 640rpx;
		font-size: 14px;
		font-family: Source Han Sans CN-Regular, Source Han Sans CN;
		font-weight: 400;
		color: #434343;

		.textarea {
			margin-bottom: 40rpx;
		}
	}

	/deep/ .uni-popup {
		z-index: 99999;
	}

	/deep/.uni-input-input {
		background: #fff !important;
	}

	/deep/ .u-upload__wrap {
		display: flex;
		align-items: center;
	}

	/deep/ .u-upload__wrap__preview__other {
		height: 80rpx !important;
		width: 80rpx !important;
	}

	/deep/ .u-upload__deletable {
		z-index: 999999999 !important;
	}

	/deep/ .u-textarea {
		width: 99% !important;
	}
	::v-deep {
		.popUp.accept {
			.contents {
				.item {
					.left {
						min-width: 240rpx;
					}
				}
			}
		}
	}
	
	/deep/ .u-radio__text {
		font-size: 28rpx!important;
	}
	/deep/ .u-icon__icon {
		font-size: 28rpx!important;
	}
</style>